from django.shortcuts import render,HttpResponse,redirect,reverse
from system.models import Account

# Create your views here.
def login(request):
      if request.method == 'POST':
            print("进入页面")
            name = request.POST['username']
            password = request.POST['password']
            print(name+":"+password)
            #根据name查询数据库，获取列表中第一个元素
            corr_user = Account.objects.filter(name=name).first()
            print(dir(corr_user))
            print("获取到信息")
            if password == corr_user.password:
                  print('登录成功')
                  return HttpResponse('登录成功')
            
      return render(request,"system/login.html")
      
def logon(request):
      return HttpResponse('logon')

def logout(request):
      return redirect(reverse('login'))

def index(request):
      print('进入index')
      return redirect(reverse('login'))